 
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<script type="text/javascript">
		/*点击时间联动checkbox*/
		function onClick(e, treeId, treeNode) {
			e.preventDefault()
			return false;
		}	
		/*checkbox选中状态id记录*/
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("permissionZtree"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].id + ",";
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			var roleId = $("#permissionIdStr");
			roleId.attr("value", v);
		}
		/**ztree设置*/
		 var setting = {
		  view: {
		    dblClickExpand: false,//双击节点时，是否自动展开父节点的标识
		    showLine: true,//是否显示节点之间的连线
		    fontCss:{'color':'black','font-weight':'bold'},//字体样式函数
		    selectedMulti: false //设置是否允许同时选中多个节点
		  },
		  view: {
				dblClickExpand: false
			},
		  check:{
		    chkboxType:  { "Y" : "s", "N" : "s" },
		    chkStyle: "checkbox",//复选框类型
		    enable: true //每个节点上是否显示 CheckBox 
		  },
		  data: {
		    simpleData: {//简单数据模式
		      enable:true,
		      idKey: "id",
		      pIdKey: "parentId",
		      rootPId: null
		    }
		  },
       	 callback: {
			onClick: onClick,
			onCheck: onCheck
		 }
		};  
		
		/**
		 * 加载树形结构数据
		 */
	  	function onLoadZTree(){
		  var treeNodes;
		  $.ajax({
		    async:false,//是否异步
		    cache:false,//是否使用缓存
		    data:{roleId:$('#roleId').val()},
		    type:'POST',//请求方式：post
		    dataType:'json',//数据传输格式：json
		    url:"<%=request.getContextPath()%>/sys/sysRolePermissionAction/toEdit",//请求的action路径
		    error:function(){
		      //请求失败处理函数
		      alert('亲，请求失败！');
		    },
		    success:function(data){
		      console.log(data);
		      //请求成功后处理函数
		     treeNodes = data;//把后台封装好的简单Json格式赋给treeNodes
		     var t = $("#permissionZtree");
		  	 t = $.fn.zTree.init(t, setting, treeNodes); 
		  	 var v = "";
		  	 for ( var i in data) {
		  	 	if(data[i].checked == true){
		  	 		v += data[i].id + ",";
		  	 	}
			 }
			 if (v.length > 0 ) v = v.substring(0, v.length-1);
		     var roleId = $("#permissionIdStr");
			 roleId.attr("value", v);
		    }
		  });
		} 
		
		/**
		 * 页面初始化
		 */
		 $(document).ready(function(){
		  onLoadZTree();
		}); 
</script>

<div class="bjui-pageContent">
   <form action="${ctx}/sys/sysRolePermissionAction/doSave" class="pageForm" data-toggle="validate"> 
        <input type="hidden" id="op" name="op" value="${param.op}">
        <input type="hidden" id="roleId" name="roleId" value="${param.roleId}">
        <input type="hidden" id="permissionIdStr" name="permissionIdStr" value="">
        <ul id="permissionZtree" class="ztree" style="padding-left: 45px"></ul>
  </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
        <li><button type="submit" class="btn-default" data-icon="save">保存</button></li>
    </ul>
</div>